from common.BasePages import BasePage


class Configuration(BasePage):
    # 组态管理
    def configuration_url(self):
        self.goto_url("visualizationCenter/visualizationCenter")

    def create_configuration(self):
        self.page.get_by_role("button", name="新增").click()
        self.page.get_by_role("dialog", name="新增").get_by_placeholder("请输入项目名称").click()
        self.page.get_by_role("listitem").filter(has_text="张院龙").click()
        self.page.get_by_role("dialog", name="新增").get_by_placeholder("请输入名称").click()
        self.page.get_by_role("dialog", name="新增").get_by_placeholder("请输入名称").fill("张院龙组态")
        self.page.get_by_role("button", name="确 定").click()
        self.assert_alert_content("添加组态成功")

    def edit_configuration_name(self):
        self.page.get_by_role("cell", name="张院龙组态 ").locator("i").click()
        self.page.get_by_role("textbox", name="请输入名称，40字内").fill("张院龙组态2")
        self.page.get_by_role("button", name="确 定").click()
        self.assert_alert_content("编辑组态成功")

    def edit_configuration(self):
        self.page.get_by_role("cell", name="张院龙组态 ").locator("i").click()
        self.page.get_by_role("textbox", name="请输入名称，40字内").fill("张院龙组态2")
        self.page.get_by_role("button", name="确 定").click()
        self.page.get_by_text("编辑组态成功").click()
        with self.page.expect_popup() as page2_info:
            self.page.get_by_role("row", name="  ", exact=True).locator("i").first.click()
        page2 = page2_info.value
        page2.get_by_role("button", name=" 发布").click()
        self.assert_alert_content("发布成功！")

    def delete_configuration(self):
        self.page.get_by_role("row", name="  ", exact=True).locator("i").nth(1).click()
        self.page.get_by_role("button", name="确定").click()
        self.assert_alert_content("删除成功!")

    def set_default(self):
        # 设置默认
        self.click_more_functions("组态管理","设置默认")
        self.page.get_by_role("button", name="确定").click()
        self.assert_alert_content("设置成功!")

    def cat_history(self):
        # 查看历史
        self.click_more_functions("组态管理","查看历史")
